const app = getApp();
import { getUnId, unLogin, updateUnionid, getHistoryUnId } from '../../utils/requestApi.js';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    
  },

  /**
   * 组件的初始数据
   */
  data: {
    isAut: false, //是否授权
  },

  ready(){
    let _this = this;
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userInfo'] && !app.data.unionId) _this.setData({ isAut: true })
        else {
          wx.getUserInfo({
            success: (res2)=> {
              if (!app.data.kjid && !app.data.unionId) {
                app.data.userAvatar = res2.userInfo.avatarUrl
                app.data.userName = res2.userInfo.nickName
                app.toLogin(res2.encryptedData, res2.iv)
              }
              if (app.data.kjid) app.kjToLogin(res2.encryptedData, res2.iv)
            }
          })
        }
      }
    })      
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //关闭modal
    confirm(){
      this.setData({ isAut: false })
    },
    
    // 获取用户信息
    bindgetuserinfo(e){
      this.setData({ isAut: false })
      if (!app.data.kjid && !app.data.unionId) {
        app.data.userAvatar = e.detail.userInfo.avatarUrl
        app.data.userName = e.detail.userInfo.nickName
        app.toLogin(e.detail.encryptedData, e.detail.iv)
      }
      if (app.data.kjid) app.kjToLogin(e.detail.encryptedData, e.detail.iv)
    }
  }
})
